package com.example.service.impl;

import com.example.domain.po.Hospital;
import com.example.domain.vo.CourseVo;
import com.example.mapper.HospitalMapper;
import com.example.service.HospitalService;
import com.example.util.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalMapper hospitalMapper;

    @Override
    public Hospital findByDockerId(Integer dockerId) {
        return hospitalMapper.findByDockerId(dockerId);
    }

    @Override
    public PageBean<Hospital> list(Integer pageNum, Integer pageSize, String name) {
        PageBean<Hospital> pb = new PageBean<>();
        PageHelper.startPage(pageNum, pageSize);
        List<Hospital> list = hospitalMapper.list(name);
        Page<Hospital> p = (Page<Hospital>)list ;
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;

    }

    @Override
    public void add(Hospital hospital) {
        if (hospital.getId()==null){

            hospitalMapper.add(hospital);
        }else {
            hospitalMapper.update(hospital);
        }
    }

    @Override
    public void del(Integer id) {
        hospitalMapper.del(id);
    }

    @Override
    public List<Hospital> findAll() {
        return hospitalMapper.findAll();
    }
}
